from typing import List


class Solution:
    def generateMatrix(self, n: int) -> List[List[int]]:
        res = [[0 for _ in range(n)] for _ in range(n)]
        t, b, l, r = 0, n - 1, 0, n - 1
        s = 1
        while r - l >= 1 and b - t >= 1:
            # 上
            for i in range(l, r + 1):
                res[t][i] = s
                s += 1
            t += 1
            print(res)
            # 右
            for i in range(t, b + 1):
                res[i][r] = s
                s += 1
            r -= 1
            print(res)
            # 下
            for i in range(r, l, -1):
                res[b][i] = s
                s += 1
            b -= 1
            # 左
            for i in range(b + 1, t - 1, -1):
                res[i][l] = s
                s += 1
            l += 1
        if n % 2:
            mid = n // 2
            res[mid][mid] = n * n
        return res
